package com.kucai.yifaqapp.presenter.fragment;

import android.widget.Toast;

import com.kucai.yifaqapp.global.HttpAdress;
import com.kucai.yifaqapp.model.CustomObserver;
import com.kucai.yifaqapp.model.network.HttpJsonUtils;
import com.kucai.yifaqapp.model.network.entity.res.ResGameDetails;
import com.kucai.yifaqapp.model.network.entity.res.ResMoney;
import com.kucai.yifaqapp.model.network.entity.res.ResSetbet;
import com.kucai.yifaqapp.model.network.entity.res.Reschongqingshishicai;
import com.kucai.yifaqapp.model.network.entity.res.Reskuailefenfencai;
import com.kucai.yifaqapp.model.network.entity.res.Resmiaosushishicai;
import com.kucai.yifaqapp.model.network.entity.res.Resqqfenfencai;
import com.kucai.yifaqapp.model.network.entity.res.Ressanfenssc;
import com.kucai.yifaqapp.model.network.entity.res.Restengxunfenfencai;
import com.kucai.yifaqapp.model.network.entity.res.Resxinjiangshishicai;
import com.kucai.yifaqapp.ui.fragment.gameFragment.SSCFragment;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Administrator on 2018/12/10.
 */

public class SSCFragmentPresenter extends BaseFragmentPresenter<SSCFragment> {


    public SSCFragmentPresenter(SSCFragment mFragment) {
        super(mFragment);
    }


    //获取游戏详情
    public void getgamesdetail(String gameid) {
        HttpJsonUtils.getHttpApiInstance()
                .getgamesdetail(HttpAdress.getuseAdress() + "api/m/lottery/getNextIssue.do", gameid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResGameDetails>() {
                    @Override
                    protected void onCustomNext(ResGameDetails resGameDetails) {
                        if (null != resGameDetails.data && resGameDetails.code == 0) {
                            if (("秒速时时彩").equals(resGameDetails.data.game_name) || ("重庆时时彩").equals(resGameDetails.data.game_name)
                                    || ("新疆时时彩").equals(resGameDetails.data.game_name) || ("QQ分分彩").equals(resGameDetails.data.game_name)
                                    || ("腾讯分分彩").equals(resGameDetails.data.game_name)
                                    || ("三分时时彩").equals(resGameDetails.data.game_name)
                                    || ("快速时时彩").equals(resGameDetails.data.game_name)) {
                                mFragment.Lottery(resGameDetails);
                            } else {
                                Toast.makeText(mFragment.getContext(), "官方关闭", Toast.LENGTH_SHORT).show();
                            }

                        } else {
                            //开奖失败
                            mFragment.openfail();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                        mFragment.openfail();
                    }
                });
    }

    //获取游戏详情
    public void getgamesdetail1(String gameid) {
        HttpJsonUtils.getHttpApiInstance()
                .getgamesdetail(HttpAdress.getuseAdress() + "api/m/lottery/getNextIssue.do", gameid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResGameDetails>() {
                    @Override
                    protected void onCustomNext(ResGameDetails resGameDetails) {
                        if (null != resGameDetails.data && resGameDetails.code == 0) {
                            if (("秒速时时彩").equals(resGameDetails.data.game_name) || ("重庆时时彩").equals(resGameDetails.data.game_name)
                                    || ("新疆时时彩").equals(resGameDetails.data.game_name) || ("QQ分分彩").equals(resGameDetails.data.game_name)
                                    || ("腾讯分分彩").equals(resGameDetails.data.game_name)
                                    || ("三分时时彩").equals(resGameDetails.data.game_name)
                                    || ("快速时时彩").equals(resGameDetails.data.game_name)) {

                                mFragment.Lottery1(resGameDetails);
                            } else {
                                Toast.makeText(mFragment.getContext(), "官方关闭", Toast.LENGTH_SHORT).show();
                            }

                        } else {
                            mFragment.openfail();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                        mFragment.openfail();
                    }
                });
    }

    //下注
    public void Betbet(final String data, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .Betbet(HttpAdress.getuseAdress() + "api/m/lottery/bet.do", data, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResSetbet>(mFragment) {
                    @Override
                    protected void onCustomNext(ResSetbet resOods) {

                        if ("200".equals(resOods.code)) {
                            mFragment.betsuccses();
                        } else {
                            Toast.makeText(mFragment.getContext(), resOods.msg, Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //获取余额
    public void getmoney(String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getmoney(HttpAdress.getuseAdress() + "api/m/user/getMoney", token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResMoney>() {
                    @Override
                    protected void onCustomNext(ResMoney resOods) {
                        if (resOods.code == 0) {
                            mFragment.moneychange(resOods);
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }


    //新疆时时彩
    public void getxinjiangshishicaioddes(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getxinjiangshishicaioddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Resxinjiangshishicai>() {
                    @Override
                    protected void onCustomNext(Resxinjiangshishicai resOods) {
                        if (resOods.code.equals("0")) {
                            mFragment.setdataxinjiangshishicai(resOods.data);
                        } else if (resOods.code.equals("60011")) {
                            mFragment.restartlogin();
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //重庆时时彩

    public void getchongqingshishicaioddes(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getchongqingshishicaioddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Reschongqingshishicai>() {
                    @Override
                    protected void onCustomNext(Reschongqingshishicai resOods) {
                        if (resOods.code.equals("0")) {
                            mFragment.setdatachongqingshishicai(resOods.data);
                        } else if (resOods.code.equals("60011")) {
                            mFragment.restartlogin();
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }
    //秒速时时彩

    public void getmiaosushishicaioddes(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getmiaosushishicaioddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Resmiaosushishicai>() {
                    @Override
                    protected void onCustomNext(Resmiaosushishicai resOods) {
                        if (resOods.code.equals("0")) {
                            mFragment.setdatamiaosushishicai(resOods.data);
                        } else if (resOods.code.equals("60011")) {
                            mFragment.restartlogin();
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    /**
     * 腾讯分分彩
     *
     * @param gameid
     * @param token
     */
    public void gettengxunfenfencaioddes(String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .gettengxunshishicaioddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Restengxunfenfencai>() {
                    @Override
                    protected void onCustomNext(Restengxunfenfencai resOods) {
                        if (resOods.code.equals("0")) {
                            mFragment.setdatatengxunfenfencai(resOods.data);
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //qq分分彩
    public void getqqfenfencaioddes(String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getqqfenfencaioddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Resqqfenfencai>() {
                    @Override
                    protected void onCustomNext(Resqqfenfencai resOods) {
                        if (resOods.code.equals("0")) {
                            mFragment.setdataqqfenfencai(resOods.data);
                        } else if (resOods.code.equals("60011")) {
                            mFragment.restartlogin();
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //快乐分分彩
    public void getkuailefenfencaioddes(String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getkuailefenfencaioddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Reskuailefenfencai>() {
                    @Override
                    protected void onCustomNext(Reskuailefenfencai resOods) {
                        if (resOods.code.equals("0")) {
                            mFragment.setdatakuailefenfencai(resOods.data);
                        } else if (resOods.code.equals("60011")) {
                            mFragment.restartlogin();
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //sanfen
    public void getsanfenssc(String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getsanfenssc(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Ressanfenssc>() {
                    @Override
                    protected void onCustomNext(Ressanfenssc resOods) {
                        if (resOods.code==0) {
                            mFragment.setsanfenssc(resOods.data);
                        } else if (resOods.code==60011) {
                            mFragment.restartlogin();
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }
}